/* reoprp40.p - EMPLOYEE PRODUCTIVITY REPORT                                  */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Id:: reoprp40.p 2366 2010-11-10 01:47:19Z zzh                          $: */
/*V8:ConvertMode=FullGUIReport                                                */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 03/01/95   BY: WUG *G0G3*                */
/* REVISION: 7.3      LAST MODIFIED: 03/14/95   By: DZN *G0G8*                */
/* REVISION: 8.6      LAST MODIFIED: 10/22/97   BY: ays *K14J*                */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 06/05/98   BY: *J2NB* A. Licha           */
/* REVISION: 8.6E     LAST MODIFIED: 07/17/98   BY: *L047* Santhosh Nair      */
/* REVISION: 8.6E     LAST MODIFIED: 10/12/98   BY: *L0BY* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *GA37*                    */
/* Revision: 1.11.1.3     BY: Hualin Zhong       DATE: 05/30/01 ECO: *N0YY*   */
/* Revision: 1.11.1.4     BY: Manisha Sawant     DATE: 08/20/01 ECO: *P01N*   */
/* Revision: 1.11.1.5     BY: Amit Chaturvedi    DATE: 03/08/02 ECO: *N1CB*   */
/* Revision: 1.11.1.7     BY: Paul Donnelly (SB) DATE: 06/28/03 ECO: *Q00K*   */
/* $Revision: 1.11.1.8 $  BY: Katie Hilbert      DATE: 04/13/07 ECO: *R0C6*   */
/*-Revision end---------------------------------------------------------------*/

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DISPLAY TITLE */
{us/mf/mfdtitle.i "1+ "}
{us/wo/woconsdf.i}

define variable altpart         like ptal_alt_part no-undo.
define variable altpart1        like ptal_alt_part no-undo.
define variable emp              like op_emp     no-undo.
define variable emp1             like op_emp     no-undo.
define variable part             like op_part    no-undo.
define variable part1            like op_part    no-undo.
define variable opdate           like op_date    no-undo.
define variable opdate1          like op_date    no-undo.
define variable wkctr            like op_wkctr   no-undo.
define variable wkctr1           like op_wkctr   no-undo.
define variable mach             like op_mch     no-undo.
define variable mach1            like op_mch     no-undo.
define variable run_var          like wr_run     format "->>9.999"      no-undo.
define variable setup_var        like wr_setup   format "->>9.999"      no-undo.
define variable run_eff          like wr_run     format ">>>9.99%"      no-undo.
define variable setup_eff        like run_eff    no-undo.
define variable desc1            like pt_desc1   no-undo.
define variable setup_per        like wr_setup   no-undo.
define variable std_run          like wr_run     label "Std Run" no-undo.
define variable tot_hours        as   decimal    label "Tot Hrs"
                                 format "->,>>9.9"      no-undo.
define variable std_hours        like tot_hours  label "Std Hrs" no-undo.
define variable prod_hours       like tot_hours  label "Prod Hrs"  no-undo.
define variable down_hours       like tot_hours  label "Down Hrs" no-undo.
define variable achvd_rate       as   integer    label "Act Rate"
                                 format "->>>,>>9"      no-undo.
define variable pcs_comp         like achvd_rate label "Pcs Proc"  no-undo.
define variable std_rate         like achvd_rate label "Std Rate" no-undo.
define variable shift            like op_shift   no-undo.
define variable detail           like mfc_logical label "Report Format"
                                 format "Detail/Summary"
                                 initial yes            no-undo.
define variable include_nonmilestone like mfc_logical
                                     label "Include Nonmilestone Operations" no-undo.
define variable stdhrs           as   decimal    no-undo.
define variable dwn-hours        as   decimal    no-undo.
define variable d-prod-hrs       as   decimal    no-undo.
define variable d-prod-percent   as   decimal    no-undo.
define variable d-util-percent   as   decimal    no-undo.
define variable d-attain-percent as   decimal    no-undo.
define  variable order_type_key  like lngd_key1 initial "0" no-undo.
define  variable c-lngd-dataset like lngd_det.lngd_dataset
   initial "wo_mstr" no-undo.
define variable orderType as character format "x(9)" label "Include Repetitive/Discrete/Both" no-undo.

form
   emp       colon 15      emp1      label "To" colon 49
   opdate    colon 15      opdate1   label "To" colon 49
   part      colon 15      part1     label "To" colon 49
   wkctr     colon 15      wkctr1    label "To" colon 49
   mach      colon 15      mach1     label "To" colon 49
   altpart   colon 15      label "Alt Item ID"  
   altpart1  colon 49 label "To" 
   shift     colon 15
   skip (1)
   detail    colon 35
   include_nonmilestone colon 35
   orderType colon 35 skip
with frame a side-labels width 80.

/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

for first lngd_det where lngd_dataset = c-lngd-dataset
   and lngd_field   = "orderType"
   and lngd_lang    = global_user_lang
   and lngd_key1    = order_type_key
   no-lock:
end.

if available lngd_det then
   orderType = lngd_key2.
   else
   orderType = "".

{us/wb/wbrp01.i}
repeat:

   if emp1    = hi_char  then emp1    = "".
   if opdate  = low_date then opdate  = ?.
   if opdate1 = hi_date  then opdate1 = ?.
   if part1   = hi_char  then part1   = "".
   if wkctr1  = hi_char  then wkctr1  = "".
   if mach1   = hi_char  then mach1   = "".
   if altpart1   = hi_char  then altpart1  = "".

   if c-application-mode <> 'web'
   then
      update 
         emp
         emp1
         opdate
         opdate1
         part
         part1
         wkctr
         wkctr1
         mach
         mach1
         altpart
         altpart1
         shift
         detail
         include_nonmilestone
         orderType
       with frame a
   editing:
      if frame-field = "orderType" then do:
         {us/mf/mfnp05.i lngd_det lngd_det
          "lngd_dataset   = c-lngd-dataset
           and lngd_field  = 'orderType'
           and lngd_lang   = global_user_lang"
           lngd_key2 "input orderType" }
          if recno <> ? then
             display lngd_key2 @ orderType
             with frame a.
      end.
      else do:
         status input.
         readkey.
         apply lastkey.
      end.
   end.

   /* INCLUDE FILE FOR WEB-ENABLEMENT */
   {us/wb/wbrp06.i &command = update
      &fields  = "emp emp1 opdate opdate1 part part1 wkctr
        wkctr1 mach mach1 altpart altpart1 shift detail
        include_nonmilestone orderType"
      &frm     = "a"}

   if  (c-application-mode <> 'web')
   or  (c-application-mode =  'web'
   and (c-web-request begins  'data'))
   then do:

      if emp1    = "" then emp1    = hi_char.
      if opdate  = ?  then opdate  = low_date.
      if opdate1 = ?  then opdate1 = hi_date.
      if part1   = "" then part1   = hi_char.
      if wkctr1  = "" then wkctr1  = hi_char.
      if mach1   = "" then mach1   = hi_char.
      if altpart1 = "" then altpart1  = hi_char.

      bcdparm = "".
      {us/bbi/gprun.i ""gpquote.p""
         "(input-output bcdparm,16,
           emp,emp1,string(opdate),string(opdate1),part,part1,
           wkctr,wkctr1,mach,mach1, altpart, altpart1,shift,string(detail),
           string(include_nonmilestone),
           orderType,null_char,null_char,null_char,
           null_char)"}

   end. /* IF c-application-mode <> 'web' */


  for first lngd_det where
              lngd_dataset     = c-lngd-dataset
          and lngd_field       = "orderType"
          and lngd_lang        = global_user_lang
          and lngd_key2 = orderType
       no-lock:
  end.
 if not available lngd_det
   then do:

      /* MUST BE (S)cheduled or (D)iscrete or (B)oth */
      {us/bbi/pxmsg.i &MSGNUM=10346 &ERRORLEVEL=4}

      if c-application-mode = "WEB"
      then
         return.

      else
         next-prompt
            orderType with frame a.
      undo,retry.
   end.
      order_type_key=lngd_key1.


   /* OUTPUT DESTINATION SELECTION */
   {us/gp/gpselout.i &printType                = "printer"
      &printWidth               = 132
      &pagedFlag                = " "
      &stream                   = " "
      &appendToFile             = " "
      &streamedOutputToTerminal = " "
      &withBatchOption          = "yes"
      &displayStatementType     = 1
      &withCancelMessage        = "yes"
      &pageBottomMargin         = 6
      &withEmail                = "yes"
      &withWinprint             = "yes"
      &defineVariables          = "yes"}

   /* TO PRINT PAGE HEADING */
   {us/bbi/mfphead.i}

   if shift > ""
   then do:

      form header
         getTermLabel("SHIFT",10) + ": " + shift at 61 format "x(14)"
      with frame shift width 132 page-top.
      view frame shift.

   end. /* IF shift > "" */

   for each op_hist

      where op_hist.op_domain = global_domain
      and ((op_emp   >= emp
      and   op_emp   <= emp1)
      and   op_site   = op_site
      and  (op_date  >= opdate
      and   op_date  <= opdate1)
      and  (op_part  >= part
      and   op_part  <= part1)
      and  (op_wkctr >= wkctr
      and   op_wkctr <= wkctr1)
      and  (op_mch   >= mach
      and   op_mch   <= mach1)
      and  (op_shift  = shift
      or    shift     = "")
      and  (op_qty_comp  <> 0
      or    op_act_run   <> 0
      or    op_act_setup <> 0)
      and  (include_nonmilestone
      or    op_milestone)
      and   op_type      <> "DOWN")
      and ((altpart = "" and altpart1 = hi_char)
         or can-find(first ptal_mstr where ptal_mstr.ptal_domain = global_domain
                                         and ptal_part             = op_part
                                         and ptal_alt_part         >= altpart
                                         and ptal_alt_part         <= altpart1
                                         and ptal_active))
      and (order_type_key = {&MFG_TYPE_DISCRETE_AND_REPETITIVE}
           or can-find(first wo_mstr where wo_mstr.wo_domain = global_domain
                                       and wo_lot            = op_wo_lot
                                       and (wo_mfg_type= order_type_key )))

   no-lock
      break by op_emp
            by op_date
            by op_part
            by op_wo_op
            by op_wkctr
   with frame b down width 132:

   find first ptal_mstr where ptal_mstr.ptal_domain = global_domain
                       and ptal_part             = op_part
                       and ptal_active
                       no-lock no-error.


      /* SET EXTERNAL LABELS */
      setFrameLabels(frame b:handle).

      view frame phead.

      if first-of(op_emp)
      then do:

         if page-size - line-counter < 4
         then
            page.

         display.

         put {us/bbi/gplblfmt.i &FUNC=getTermLabel(""EMPLOYEE"",16)
                         &CONCAT="': '"} op_emp.
         for first emp_mstr

            where emp_mstr.emp_domain = global_domain
             and  emp_addr = op_emp
         no-lock:
            put emp_name format "x(36)".
         end. /* FOR FIRST emp_mstr */

         if detail
            then
            put skip.

      end. /* IF FIRST-OF(op_emp) */

      if  first-of(op_date)
         and detail
      then do:

         if page-size - line-counter < 2
         then
            page.

         display.
         put " " {us/bbi/gplblfmt.i &FUNC=getTermLabel(""DATE"",8)
                             &CONCAT="': '"} op_date skip.

      end. /* IF FIRST-OF(op_date) AND detail */

      prod_hours = 0.
      if op_type <> "DOWNTIME"
      then
         prod_hours = op_act_setup + op_act_run.

      down_hours = 0.
      if op_type = "DOWNTIME"
      then
         down_hours = op_act_setup + op_act_run.

      std_hours  = op_std_run * op_qty_comp.

      accumulate op_qty_comp (total by op_wkctr).
      accumulate prod_hours  (total by op_wkctr).
      accumulate down_hours  (total by op_wkctr).
      accumulate std_hours   (total by op_wkctr).

      accumulate prod_hours  (total by op_emp).
      accumulate down_hours  (total by op_emp).
      accumulate std_hours   (total by op_emp).

      if last-of(op_wkctr)
      then do:

         assign
            tot_hours  = (accum sub-total by op_wkctr prod_hours)
                       + (accum sub-total by op_wkctr down_hours)
            pcs_comp   =  accum sub-total by op_wkctr op_qty_comp
            achvd_rate = 0.

         if (accum sub-total by op_wkctr prod_hours) <> 0
         then
            achvd_rate = pcs_comp / (accum sub-total by op_wkctr prod_hours).

         std_rate = 0.
         if (accum sub-total by op_wkctr std_hours) <> 0
         then
            std_rate = pcs_comp / (accum sub-total by op_wkctr std_hours).

         if detail
         then do:

            display op_wo_op.

            for first wr_route

               where wr_route.wr_domain = global_domain
                and  wr_lot = op_wo_lot
                and  wr_op  = op_wo_op
            no-lock:
               display wr_desc format "x(18)".
            end. /* FOR FIRST wr_route */

            assign
               stdhrs           = (accum sub-total by op_wkctr std_hours)
               dwn-hours        = (accum sub-total by op_wkctr down_hours)
               d-prod-hrs       = (accum sub-total by op_wkctr prod_hours)
               d-prod-percent   = 100 * (accum sub-total by op_wkctr std_hours)
                                / (accum sub-total by op_wkctr prod_hours)
               d-util-percent   = 100 * (accum sub-total by op_wkctr prod_hours)
                                / tot_hours
               d-attain-percent = 100 * (accum sub-total by op_wkctr std_hours)
                                / tot_hours.
            display
               op_wkctr
               pcs_comp
               std_rate
               achvd_rate
               stdhrs           label "Std Hrs" format "->,>>9.9"
               tot_hours        label "Tot Hrs"
               dwn-hours        label "Down Hrs" format "->,>>9.9"
               d-prod-hrs       label "Prod Hrs"  format "->,>>9.9"
               d-prod-percent   label "Prod %"  format "->>9.9"
               space(2)
               d-util-percent   label "Util %" format "->>9.9"
               d-attain-percent label "Attain %"  format "->>9.9 "
            with frame b.

            down 1.
            display op_part @ wr_desc.
            if available(ptal_mstr) then
            do:
               down 1 with frame b.
               put getTermLabel("ALT_NUMBER",8) + ": " + ptal_alt_part at 8 format "x(28)" skip.
            end.

         end. /* IF detail */

         accumulate tot_hours (total by op_emp).

      end. /* IF LAST-OF(op_wkctr) */

      if last-of(op_emp)
      then do:

         if page-size - line-counter < 2
         then do:
            page.
            clear frame b.
            display.
         end. /* IF page-size - line-counter < 2 */

         if detail
         then
            put {us/bbi/gplblfmt.i &FUNC=getTermLabel(""EMPLOYEE_TOTAL"",20)
                            &CONCAT="':'"} to 61.
         else
            put {us/bbi/gplblfmt.i &FUNC=getTermLabel(""TOTAL"",20)
                            &CONCAT="':'"} to 61.

         put
            (accum sub-total by op_emp std_hours)  format "->,>>9.9" to 70
            (accum sub-total by op_emp tot_hours)  format "->,>>9.9" to 79
            (accum sub-total by op_emp down_hours) format "->,>>9.9" to 88
            (accum sub-total by op_emp prod_hours) format "->,>>9.9" to 97
            100 * (accum sub-total by op_emp std_hours)
                / (accum sub-total by op_emp prod_hours)
                                                   format "->>9.9%" to 105
            100 * (accum sub-total by op_emp prod_hours)
                / (accum sub-total by op_emp tot_hours)
                                                   format "->>9.9%" to 113
            100 * ((accum sub-total by op_emp std_hours)
                *  (accum sub-total by op_emp prod_hours))
                / ((accum sub-total by op_emp prod_hours)
                *  (accum sub-total by op_emp tot_hours))
                                                   format "->>9.9%" to 121.
      end. /* IF LAST-OF(op_emp) */

      if last (op_emp)
      then do:

         if page-size - line-counter < 2
         then do:
            page.
            clear frame b.
            display.
         end. /* IF page-size - line-counter < 2 */

         put
            skip(1)
            {us/bbi/gplblfmt.i &FUNC=getTermLabel(""REPORT_TOTAL"",20)
                        &CONCAT="':'"} to 61
            (accum total std_hours)  format "->,>>9.9" to 70
            (accum total tot_hours)  format "->,>>9.9" to 79
            (accum total down_hours) format "->,>>9.9" to 88
            (accum total prod_hours) format "->,>>9.9" to 97
            100 * (accum  total std_hours)
                / (accum  total prod_hours)  format "->>9.9%" to 105
            100 * (accum  total prod_hours)
                / (accum  total tot_hours)   format "->>9.9%" to 113
            100 * ((accum total std_hours)
                *  (accum total prod_hours))
                / ((accum total prod_hours)
                *  (accum total tot_hours))  format "->>9.9%" to 121.
      end. /* IF LAST (op_emp) */

      /* REPORT EXIT FOR PAGING INCLUDE FILE */
      {us/mf/mfrpchk.i}

   end. /* FOR EACH op_hist */

   /* REPORT TRAILER */
   {us/mf/mfrtrail.i}

end. /* REPEAT: */

{us/wb/wbrp04.i &frame-spec = a}

